<template>
  <UploadExcel :before-upload="beforeUpload" :on-success="onSuccess" />
</template>

<script>
import { importEmployee } from '@/api/employees'
export default {
  methods: {
    beforeUpload() {
      console.log(2)
      return true
    },
    async onSuccess({ results }) {
      const userRelations = {
        '入职日期': 'timeOfEntry',
        '手机号': 'mobile',
        '姓名': 'username',
        '转正日期': 'correctionTime',
        '工号': 'workNumber'
      }
      const res = results.map(item => {
        const obj = {}
        Object.keys(userRelations).forEach(key => {
          obj[userRelations[key]] = item[key]
        })
        return obj
      })
      console.log(res)
      try {
        await importEmployee()
        this.$router.push('/employees')
        this.$message.success('导入成功')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style>

</style>
